import pandas as pd
from utils.errorManager import FatigueManager
from utils.dataManager import *

fatigue_manager = FatigueManager()
fatigue_manager.Threshold_Dalay = 0.7
fatigue_manager.Threshold_PressMiss = 0.3
fatigue_manager.Threshold_PressError = 0.3
if __name__ == '__main__':
    # df = pd.read_csv("dataset/2021-09-16_00-06-20__2021-09-16_00-06-56.csv")
    df = pd.read_csv("dataset/2021-09-15_23-10-18__2021-09-15_23-10-56.csv")
    #将df分装成beat_table
    beat_table = df_2_beat_table(df)

    window_size = 10
    i = len(df) - window_size
    while(i >= 0):
        w_index = len(df) - i
        bt = slice_beat_table_2_df(beat_table, w_index, window_size)  #滑动

        fatigue_manager.calculate_pressDelay(bt)
        fatigue_manager.calculate_errorPress(bt)
        fatigue_manager.calculate_missPress(bt)

        print(f"delay={fatigue_manager.delay}, error={fatigue_manager.pressError}, miss={fatigue_manager.pressMiss}")

        '''疲劳判断（级别从高到低分）'''
        if (fatigue_manager.pressMiss > fatigue_manager.Threshold_PressMiss):
            print("fatigue Level3")
        elif (fatigue_manager.pressError > fatigue_manager.Threshold_PressError):
            print("fatigue Level2")
        elif (fatigue_manager.delay > fatigue_manager.Threshold_Dalay):
            print("fatigue Level1")
        else:
            print("alert state")

        print()
        i -= 1
